package com.etoak.controller;

import com.etoak.api.UploadService;
import com.etoak.common.core.vo.PageVO;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.service.DishesService;
import com.etoak.vo.DishesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/dishes")
public class DishesController {
    @Autowired
    UploadService uploadService;
    @Autowired
    DishesService dishesService;

    @PostMapping("/image")
    public ResultVO uploadImage(MultipartFile file) {
        return uploadService.uploadImage(file);
    }

    @PostMapping
    public ResultVO addDishes(@Validated @RequestBody Dishes dishes) {
        return dishesService.add(dishes);
    }

    @GetMapping("/list")
    public ResultVO<PageVO<DishesVO>> list(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            Dishes dishes
    ) {
        return dishesService.getList(pageNum, pageSize, dishes);
    }
    @PutMapping("/{id}")
    public ResultVO updateDishes(@PathVariable Integer id, @RequestBody Dishes dishes) {
        return dishesService.updateDishes(id,dishes);
    }
    @DeleteMapping("/{id}")
    public ResultVO deleteDishes(@PathVariable Integer id) {
        return dishesService.deleteDishes(id);
    }

}
